package com.meilingcloud.research.controller;

import com.meilingcloud.common.annotation.Log;
import com.meilingcloud.common.core.controller.BaseController;
import com.meilingcloud.common.core.domain.AjaxResult;
import com.meilingcloud.common.enums.BusinessType;
import com.meilingcloud.common.utils.SecurityUtils;
import com.meilingcloud.research.domain.RwsFollowTemp;
import com.meilingcloud.research.service.IRwsFollowTempService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;

/**
 * 随访模板 Controller
 *
 * @author chenl
 * @date 2021-04-21
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/research/followTemp")
public class RwsFollowTempController extends BaseController {

    private final IRwsFollowTempService iRwsFollowTempService;

    /**
     * 查询随访模板 列表
     */
    @PreAuthorize("@ss.hasPermi('research:followTemp:list')")
    @GetMapping("/list")
    public AjaxResult list(RwsFollowTemp rwsFollowTemp) {
        List<RwsFollowTemp> list = iRwsFollowTempService.queryList(rwsFollowTemp);
        return AjaxResult.success(list);
    }

    /**
     * 获取随访模板 详细信息
     */
    @PreAuthorize("@ss.hasPermi('research:followTemp:query')")
    @GetMapping(value = "/{followTempId}")
    public AjaxResult getInfo(@PathVariable("followTempId") Long followTempId) {
        return AjaxResult.success(iRwsFollowTempService.getById(followTempId));
    }

    /**
     * 新增随访模板
     */
    @PreAuthorize("@ss.hasPermi('research:followTemp:add')")
    @Log(title = "随访模板 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody RwsFollowTemp rwsFollowTemp) {
        rwsFollowTemp.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iRwsFollowTempService.save(rwsFollowTemp));
    }

    /**
     * 修改随访模板
     */
    @PreAuthorize("@ss.hasPermi('research:followTemp:edit')")
    @Log(title = "随访模板 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody RwsFollowTemp rwsFollowTemp) {
        rwsFollowTemp.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(iRwsFollowTempService.updateById(rwsFollowTemp));
    }

    /**
     * 删除随访模板
     */
    @PreAuthorize("@ss.hasPermi('research:followTemp:remove')")
    @Log(title = "随访模板 ", businessType = BusinessType.DELETE)
    @DeleteMapping("/{followTempIds}")
    public AjaxResult remove(@PathVariable Long[] followTempIds) {
        return toAjax(iRwsFollowTempService.removeByIds(Arrays.asList(followTempIds)));
    }
}
